<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require("../Vendor/twitteroauth/twitteroauth.php");


session_start();

class AccountsController extends AppController {

    public $helpers = array('Html', 'Form');
    public $helpers1 = array('Js' => array('DragDropHelpers'));
    public $helpers2 = array('Js' => array('EventHelpers'));
    public $helpers3 = array('Js' => array('permissionForm'));
    public $helpers4 = array('css' => array('permission'));

    public function index() {

        $this->set('accounts', $this->Account->find('all'));
    }
    
        public function assign_pos() {
        $user = new User();
        $arrayusers = $user->getAllusers();
        $this->set('arrayusers', $arrayusers);
        $length = count($arrayusers);
        $this->set('length', $length);
        /** print_r($arrayusers); */
        
          
    }

    function isAuthorized($accountID) {
        if (!($this->Account->isUnique('accID', $accountID))) {
            return True;
        } else {
            return False;
        }
        //$account = $this->Account->query("select oauthToken, oauth_token_secret from accounts Account where Account.accID='" . $accountID . "'");
    }

    function connectionRequest($accountID) {
        if ($this->isAuthorized($accountID)) {
            $account = $this->Account->query("select oauthToken, oauth_token_secret from accounts Account where Account.accID='" . $accountID . "'");
            $connection = new TwitterOAuth('owy8FcsCHrjDVt88taZ4g', 'JfUzU9bJzr0UcLp8gsnRoRhAYpU0ZXnrExCwaxHHEM', $account['0']['Account']['oauthToken'], $account['0']['Account']['oauth_token_secret']);
            $content = $connection->get('account/verify_credentials');
            return $connection;
        }
        else
            return FALSE;
    }
	}
?>

